package cn.kgc.watch.service.impl;

import cn.kgc.watch.entity.CommoditySku;
import cn.kgc.watch.entity.Order;
import cn.kgc.watch.entity.OrderDetail;
import cn.kgc.watch.entity.ProductComments;
import cn.kgc.watch.mapper.OrderMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import cn.kgc.watch.mapper.ProductCommentsMapper;
import cn.kgc.watch.service.ProductCommentsService;

import java.util.ArrayList;
import java.util.List;

@Service
public class ProductCommentsServiceImpl implements ProductCommentsService{

    @Resource
    private ProductCommentsMapper productCommentsMapper;
    @Resource
    private OrderMapper orderMapper;

    @Override
    public List<ProductComments> selectById(Integer id) {
        return this.productCommentsMapper.selectById(id);
    }

    @Override
    public List<ProductComments> findOrder(Integer id) {
        return this.productCommentsMapper.selectOrder(id);
    }

    @Override
    public void add(ProductComments productComments) {
        this.productCommentsMapper.insert(productComments);
    }

    @Override
    public List<CommoditySku> selectOrderSku(Integer userId) {
        List<Order> orderList = this.orderMapper.selectOrderByUserId(userId);
        List<CommoditySku> commoditySkuList = new ArrayList<>();
        for (Order order : orderList) {
            List<OrderDetail> f = order.getOrderDetailList();
            for (OrderDetail orderDetail : f) {
               commoditySkuList.add(orderDetail.getCommoditySku());
            }
        }
        return commoditySkuList;
    }

    @Override
    public void modify(Integer commentId) {
        this.productCommentsMapper.update(commentId);
    }

}
